% path = '/Users/jabeerahmed/Desktop/Tests Projects/CvCommandLine/images/';
cd('images');
clc

%%
h = 16;w = 16;
h*2*w*2
for i = 1:1360
num = num2str(i);
im_last = imread(['imLast_' num '.jpg']);
im_curr = imread(['imCurr_' num '.jpg']);
im_last = imresize(im_last,[60 60]);
im_curr = imresize(im_curr,[60 60]);
figure(1);clf;
dif_im = abs(im_curr - im_last) > 10;
G = fspecial('gaussian',[5 5],2);
%# Filter it
Ig = imfilter(dif_im,G,'same');
imshow(im_curr);
colormap gray

[X,Y] = meshgrid(1:size(dif_im,2),1:size(dif_im,1));
x = round(mean(X(Ig)));
y = round(mean(Y(Ig)));

hold on;
plot(x,y,'r.')

x = [x-w x+w x+w x-w x-w]; 
y = [y+h y+h y-h y-h y+h]; 

hold on;
plot(x,y,'r-')
pause(0.1)
end
%%